package com.hd.hdxgddcommon.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class JsonUtils {

    public static Map<String, Object> getMapFromJson(String jsonString) {

        JSONObject jsonObject = JSONObject.parseObject(jsonString);
        Map<String, Object> map = new HashMap<>();
        Set<Map.Entry<String, Object>> iter = jsonObject.entrySet();
        for (Map.Entry<String, Object> entry : iter) {
            map.put(entry.getKey(), entry.getValue());
        }

        return map;
    }

    public static <T> T tran(Object o, Class<T> tClass) {
        if (o instanceof JSONObject) {
            return ((JSONObject) o).toJavaObject(tClass);
        } else {
            return null;
        }
    }
}
